/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.clebersantos.dao;

import br.com.clebersantos.pojos.Indicadores;
import br.com.clebersantos.pojos.Produto;
import br.com.clebersantos.util.HibernateUtil;
import java.io.Serializable;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Projections;

/**
 *
 * @author Jurema
 */
public class IndicadoresDAO implements Serializable {

    Indicadores in = new Indicadores();
    Session sessao;
    Transaction tx;

    public void totalValorEstoque() {
        try {

            sessao = HibernateUtil.getSessionFactory().openSession();
            tx = sessao.beginTransaction();
            
            Criteria cri = sessao.createCriteria(Produto.class);
            
            String soma = cri.setProjection(Projections.sum("precoCompra")).uniqueResult().toString();
            
            System.out.println("Soma: " + soma);
            
            in.setValorTotalEstoque(soma);
            in.setId(6);
            
            sessao.update(in);
            tx.commit();

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            sessao.close();
        }
    }

}
